package com.lbt.framework.dao;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lbt.framework.exception.MyException;
import com.lbt.framework.general.Page;
import com.lbt.framework.general.Paging;
import com.lbt.framework.general.Searching;
import com.lbt.framework.general.Sorting;

/**
 * 
 * @author mo_yq5@163.com
 * @date 2013-1-30
 * 
 */
public abstract class BasicService<T> implements Service<T> {
	
	private static Logger log = LoggerFactory.getLogger(BasicService.class);
	
	protected abstract Dao<T> getDao();

	@Override
	public T one(Serializable id) {
		log.debug("get: {}", id.getClass().getName());
		return getDao().get(id);
	}

	@Override
	public void delete(Serializable id) {
		log.debug("delete: {}", id.getClass().getName());
		getDao().delete(getDao().get(id));
	}

	@Override
	public void delete(T entity) {
		log.debug("delete: {}", entity.getClass().getName());
		getDao().delete(entity);
	}

	@Override
	public T saveOrUpdate(T entity) {
		log.debug("saveOrUpdate: {}", entity.getClass().getName());
		return getDao().saveOrUpdate(entity);
	}

	@Override
	public T save(T entity) {
		log.debug("save: {}", entity.getClass().getName());
		return getDao().save(entity);
	}
	
	@Override
	public T persist(T entity) {
		log.debug("persist: {}", entity.getClass().getName());
		return getDao().persist(entity);
	}

	@Override
	public T update(T entity) {
		log.debug("update: {}", entity.getClass().getName());
		return getDao().update(entity);
	}

	@Override
	public T merge(T entity) {
		log.debug("merge: {}", entity.getClass().getName());
		return getDao().merge(entity);
	}
	
	@Override
	public List<T> list(T entity) {
		log.debug("list: {}", entity.getClass().getName());
		return getDao().listByExample(entity);
	}

	@Override
	public List<T> list(T entity, Sorting sort) {
		log.debug("list: {}", entity.getClass().getName());
		return getDao().listByExample(entity, sort);
	}

	@Override
	public List<T> list(T entity, Sorting sort, String searchWord) {
		log.debug("list: {}", entity.getClass().getName());
		return getDao().listByExample(entity, sort, searchWord);
	}
	
	@Override
	public Page<T> list(T entity, Paging page) {
		log.debug("list: {}", entity.getClass().getName());
		return getDao().listByExample(entity, page);
	}

	@Override
	public Page<T> list(T entity, Paging page, String searchWord) {
		log.debug("list: {}", entity.getClass().getName());
		return getDao().listByExample(entity, page, searchWord);
	}

	@Override
	public Page<T> list(T entity, Searching search) {
		log.debug("list: {}", entity.getClass().getName());
		return getDao().listByExample(entity, search);
	}

	@Override
	public int count(T entity) {
		log.debug("count: {}", entity.getClass().getName());
		return getDao().countByExample(entity);
	}

	@Override
	public int count(T entity, String searchWord) {
		log.debug("count: {}", entity.getClass().getName());
		return getDao().countByExample(entity, searchWord);
	}

	
	@Override
	public void remove(T entity) throws MyException {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public T addOrEdit(T entity) throws MyException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public T add(T entity) throws MyException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public T edit(T entity) throws MyException {
		// TODO Auto-generated method stub
		return null;
	}

}
